1
|
|
|
var ExtensibleData = require('./ExtensibleData'), |
2
|
|
|
Attribution = require('./Attribution'), |
3
|
|
|
utils = require('./utils'); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* A note about a resource. |
7
|
|
|
* |
8
|
|
|
* @constructor |
9
|
|
|
* @param {Object} [json] |
|
|
|
|
10
|
|
|
*/ |
11
|
|
|
var Note = function(json){ |
12
|
|
|
|
13
|
|
|
// Protect against forgetting the new keyword when calling the constructor |
14
|
|
|
if(!(this instanceof Note)){ |
15
|
|
|
return new Note(json); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
// If the given object is already an instance then just return it. DON'T copy it. |
19
|
|
|
if(Note.isInstance(json)){ |
20
|
|
|
return json; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
ExtensibleData.call(this, json); |
24
|
|
|
|
25
|
|
|
if(json){ |
|
|
|
|
26
|
|
|
this.setLang(json.lang); |
27
|
|
|
this.setSubject(json.subject); |
28
|
|
|
this.setText(json.text); |
29
|
|
|
this.setAttribution(json.attribution); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
}; |
32
|
|
|
|
33
|
|
|
Note.prototype = Object.create(ExtensibleData.prototype); |
34
|
|
|
|
35
|
|
|
Note._gedxClass = Note.prototype._gedxClass = 'GedcomX.Note'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Check whether the given object is an instance of this class. |
39
|
|
|
* |
40
|
|
|
* @param {Object} obj |
41
|
|
|
* @returns {Boolean} |
42
|
|
|
*/ |
43
|
|
|
Note.isInstance = function(obj){ |
44
|
|
|
return utils.isInstance(obj, this._gedxClass); |
45
|
|
|
}; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get the language identifier. |
49
|
|
|
* |
50
|
|
|
* @returns {String} lang |
51
|
|
|
*/ |
52
|
|
|
Note.prototype.getLang = function(){ |
53
|
|
|
return this.lang; |
54
|
|
|
}; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Set the language identifier. |
58
|
|
|
* |
59
|
|
|
* @param {String} lang |
60
|
|
|
* @returns {Note} This instance. |
61
|
|
|
*/ |
62
|
|
|
Note.prototype.setLang = function(lang){ |
63
|
|
|
this.lang = lang; |
64
|
|
|
return this; |
65
|
|
|
}; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the subject. |
69
|
|
|
*/ |
70
|
|
|
Note.prototype.getSubject = function(){ |
71
|
|
|
return this.subject; |
72
|
|
|
}; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Set the subject. |
76
|
|
|
* |
77
|
|
|
* @param {String} subject |
78
|
|
|
* @returns {Note} This note. |
79
|
|
|
*/ |
80
|
|
|
Note.prototype.setSubject = function(subject){ |
81
|
|
|
this.subject = subject; |
82
|
|
|
return this; |
83
|
|
|
}; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the text. |
87
|
|
|
* |
88
|
|
|
* @returns {String} text |
89
|
|
|
*/ |
90
|
|
|
Note.prototype.getText = function(){ |
91
|
|
|
return this.text; |
92
|
|
|
}; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set the text. |
96
|
|
|
* |
97
|
|
|
* @param {String} text |
98
|
|
|
* @returns {Note} This note. |
99
|
|
|
*/ |
100
|
|
|
Note.prototype.setText = function(text){ |
101
|
|
|
this.text = text; |
102
|
|
|
return this; |
103
|
|
|
}; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get the attribution. |
107
|
|
|
* |
108
|
|
|
* @returns {Attribution} |
109
|
|
|
*/ |
110
|
|
|
Note.prototype.getAttribution = function(){ |
111
|
|
|
return this.attribution; |
112
|
|
|
}; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Set the attribution |
116
|
|
|
* |
117
|
|
|
* @param {Object|Attribution} attribution |
118
|
|
|
* @returns {Note} This instance. |
119
|
|
|
*/ |
120
|
|
|
Note.prototype.setAttribution = function(attribution){ |
121
|
|
|
if(attribution){ |
122
|
|
|
this.attribution = new Attribution(attribution); |
123
|
|
|
} |
124
|
|
|
return this; |
125
|
|
|
}; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Export the object as JSON |
129
|
|
|
* |
130
|
|
|
* @return {Object} JSON object |
131
|
|
|
*/ |
132
|
|
|
Note.prototype.toJSON = function(){ |
133
|
|
|
var json = ExtensibleData.prototype.toJSON.call(this); |
134
|
|
|
|
135
|
|
|
if(this.lang){ |
136
|
|
|
json.lang = this.lang; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
if(this.subject){ |
140
|
|
|
json.subject = this.subject; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
if(this.text){ |
144
|
|
|
json.text = this.text; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
if(this.attribution){ |
148
|
|
|
json.attribution = this.attribution.toJSON(); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return json; |
152
|
|
|
}; |
153
|
|
|
|
154
|
|
|
module.exports = Note; |